﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Ext.Net;
using System.Collections.Generic;

public partial class Popup_Popup_OutSourcing1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetGubunCombo();
            SetBizCombo();

            this.GridPanel1.Show();
            this.GridPanel2.Hide();
        }
    }

    private void SetGubunCombo()
    {
        this.cbxGubun.Items.Add(new Ext.Net.ListItem("주요자재현황", "0"));
        this.cbxGubun.Items.Add(new Ext.Net.ListItem("표준DB자재", "1"));
        this.cbxGubun.SelectedIndex = 0;
    }

    private void SetBizCombo()
    {
        using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
        {
            DataSet ds = oService.Select_DDDWCLASS_NM_S2();

            this.StrBiz.DataSource = ds.Tables[0];
            this.StrBiz.DataBind();
        }
    }

    /// <summary>
    /// 소분류
    /// </summary>
    private void SetClassCombo()
    {
        using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
        {
            DataSet ds = oService.Select_DDDWCLASS_NM_S2();

            this.StrBiz.DataSource = ds.Tables[0];
            this.StrBiz.DataBind();
        }
    }

    /// <summary>
    /// 대분류
    /// </summary>
    private void SetMkClassCombo()
    {
        using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
        {
            DataSet ds = oService.Select_DDDWCLASS_NM_S2();

            this.StrBiz.DataSource = ds.Tables[0];
            this.StrBiz.DataBind();
        }
    }

    protected void ChangeGubun(object sender, DirectEventArgs e)
    {
        if (this.cbxGubun.SelectedIndex == 0)
        {
            this.GridPanel1.Show();
            this.GridPanel2.Hide();
        }
        else
        {
            this.GridPanel1.Hide();
            this.GridPanel2.Show();
        }
    }


    protected void CreateParameter(object sender, DirectEventArgs e)
    {
        string json = e.ExtraParams["Values"];

        Dictionary<string, string>[] dicValues = JSON.Deserialize<Dictionary<string, string>[]>(json);
        string strVal = string.Empty;

        foreach (Dictionary<string, string> dic in dicValues)
        {
            foreach (KeyValuePair<string, string> row in dic)
            {
                strVal += row.Value + "|";
            }
        }

        strVal = strVal.Remove(strVal.Length - 1);
        hdRowValue.Text = strVal;
    }


    #region 조회
    protected void PopListSearch(object sender, DirectEventArgs e)
    {
        if (this.cbxGubun.SelectedIndex == 0)
            SetGrid1();
        else
            SetGrid2();
    }


    protected void SetGrid1()
    {
        using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
        {
            DataSet ds = null;

            ds = oService.Select_D_DAYWRITE_POP8_1_S(Session["PROJ_CD"].ToString(), Session["DT"].ToString(), this.cbxCustomer.Text, this.tbxMat.Text, this.tbxSpec.Text);
            this.Store1.DataSource = ds.Tables[0];
            this.Store1.DataBind();
        }
    }

    protected void SetGrid2()
    {
        using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
        {
            DataSet ds = null;

            //ds = oService.Select_D_DAYWRITE_POP8_1_S(Session["PROJ_CD"].ToString(), Session["DT"].ToString(), this.cbxCustomer.Text, this.tbxMat.Text, this.tbxSpec.Text);
            //this.Store1.DataSource = ds.Tables[0];
            //this.Store1.DataBind();
        }
    }
    #endregion
}
